package com.rmb.signin.controller;

import com.rmb.common.model.response.ResponseResult;
import com.rmb.mart.entity.userinfo.UserCompany;
import com.rmb.mart.entity.userinfo.UserInfo;
import com.rmb.signin.service.MyUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName MyUserInfoController
 * @Description 注册登入密码找回
 * @Author yxs
 * @Date 2021/1/25 9:23
 **/
@RestController
@RequestMapping("/UserInfo")
public class MyUserInfoController {
    @Autowired
    private MyUserInfoService userInfoService;

    /**
     * 查询所有数据
     * @return
     */
    @GetMapping("/selectAll")
    public List selectAll(){
        return userInfoService.selectAll();
    }

    /**
     * 发送短信
     * @param phone
     * @return
     */
    @GetMapping("/SendMessage/{phone}")
    public ResponseResult sendMessage(@PathVariable("phone") String phone){
        return userInfoService.sendMessage(phone);
    }

    /**
     *查看redis中的验证码
     */
    @GetMapping("/getCode")
    public String getCode(){
        return userInfoService.getcode();
    }

    /**
     * 注册
     * @param code
     * @param userInfo
     * @return
     */
    @PostMapping("/register/{code}")
    public ResponseResult register(@PathVariable("code") String code,@RequestBody UserInfo userInfo){
        return userInfoService.register(code, userInfo);
    }

    /**
     * 完善信息
     * @param userCompany
     * @return
     */
    @PostMapping("/addcompany")
    public int addcompany(@RequestBody UserCompany userCompany){
        return userInfoService.addcompany(userCompany);
    }

    /**
     *查询完善信息表
     * @return
     */
    @GetMapping("/selectCompany")
    public List selectCompany(){
        return userInfoService.selectCompany();
    }

    /**
     * 短信验证登入
     * @param logincode
     * @param userInfo
     * @return
     */
    @PostMapping("/login/{loginCode}")
    public ResponseResult login(@PathVariable("loginCode") String logincode,@RequestBody UserInfo userInfo){
        return userInfoService.login(logincode, userInfo);
    }

    /**
     * 通过短信验证的方式进行修改密码
     * @param userPhone
     * @param retrieveCode
     * @param xpassword
     * @param qpassword
     * @return
     */
    @GetMapping("/RetrievePassword")
    public ResponseResult retrievePassword(@RequestParam("userPhone") String userPhone, @RequestParam("retrieveCode")String retrieveCode, @RequestParam("xpassword")String xpassword, @RequestParam("qpassword")String qpassword){
        return userInfoService.retrievePassword(userPhone,retrieveCode,xpassword,qpassword);
    }

    /**
     * 企业审核通过
     * @param id
     * @return
     */
    @GetMapping("/toexaminetrue/{id}")
    public ResponseResult toexaminetrue(@PathVariable("id")Long id){
        return userInfoService.toexaminetrue(id);
    }

    /**
     * 企业审核不通过
     */
    @GetMapping("/toexaminefalse/{id}")
    public ResponseResult toexaminefalse(@PathVariable("id") Long id){
        return userInfoService.toexaminefalse(id);
    }
}
